package designPattern.bridge桥接模式.demo01;

public class BagManage {

    public static void main(String[] args) {
        Color yellow = new Yellow();
        Color red = new Red();

        Bag bag = new HandBag();
        bag.setColor(yellow);
        System.out.println(bag.getName());

        Wallet wallet = new Wallet();
        wallet.setColor(red);
        System.out.println(wallet.getName());
    }
}

//实现化角色：颜色
interface Color {
    String getColor();
}
//具体实现化角色：黄色
class Yellow implements Color {
    public String getColor() {
        return "yellow";
    }
}
//具体实现化角色：红色
class Red implements Color {
    public String getColor() {
        return "red";
    }
}

//抽象化角色：包
abstract class Bag {
    protected Color color;
    public void setColor(Color color) {
        this.color = color;
    }
    public abstract String getName();
}
//扩展抽象化角色：挎包
class HandBag extends Bag {
    public String getName() {
        return color.getColor() + "HandBag";
    }
}
//扩展抽象化角色：钱包
class Wallet extends Bag {
    public String getName() {
        return color.getColor() + "Wallet";
    }
}
